package JsoupXmlDtd;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.lang.String;
/*
   快捷查询方式:
      1:selector:选择器
      2:XPath

*/

public class demo04_Jsoup {
    public static void main(String[] args) throws IOException {
        //2获取Document对象
        //2.1获取03_student.xml的路径path
        String aa = demo04_Jsoup.class.getClassLoader().getResource("03_student.xml").getPath();
        //2.2解析xml文档,加载文档进内存,获取dom树--->Document
        Document bb = Jsoup.parse(new File(aa), "utf-8");

        //查询name标签
        Elements cc = bb.select("name");
        System.out.println(cc);
        System.out.println("===================");
        //查询id值为itcast的元素
        Elements dd = bb.select("#itcast");
        System.out.println(dd);
        System.out.println("===================");
        //获取student标签且number属性值为a001的age子标签
        //获取student标签并且number属性值为a001
        Elements ee = bb.select("student[number=\"a001\"]");
        System.out.println(ee);
        System.out.println("===================");
        //获取age子标签
        Elements ff = bb.select("student[number=\"a001\"] > age");
        System.out.println(ff);
    }
}
